<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>在线考试平台</title>
    <link rel="shortcut icon" href="static/layui/images/exam.png" type="image/x-icon">
    <link rel="stylesheet" href="static/layui/css/font.css">
    <link rel="stylesheet" href="static/layui/css/xadmin.css">
    <script src="static/layui/lib/layui/layui.js"></script>
    <script src="static/layui/js/xadmin.js"></script>
    <script src="static/layui/js/jquery.min.js"></script>

</head>

<body>
<div class="layui-fluid">
    <div class="layui-row layui-col-space15" style="background: #f7f8fc">
        <div class="layui-col-md12">
            <div class="layui-card">
                <div class="layui-card-header">考试信息</div>
                <div class="layui-card-body " id="exam_mes">

                </div>
            </div>
        </div>
    </div>
    <div class="layui-row layui-col-space15" style="background: #f7f8fc">
        <div class="layui-col-md12">
            <div class="layui-card">
                <div class="layui-card-header">考生列表</div>
                <div class="layui-card-body">
                    <div class="layui-tab layui-tab-brief" lay-filter="user_type">
                        <ul class="layui-tab-title">
                            <li class="layui-this" value="0">未完成</li>
                            <li value="1">已完成</li>
                        </ul>
                        <div class="layui-tab-content" id="table_content">
                            <table class="layui-hide" id="no_finish_user_list" lay-filter="no_finish_user_list"></table>
                        </div>
                        <script type="text/html" id="barDemo">
                            <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del">移除该考生</a>
                        </script>

                        <script type="text/html" id="barDemo1">
                            <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="do_review" >审阅</a>
                            <a class="layui-btn layui-btn-xs" lay-event="do_look" >查看</a>
                        </script>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>

</body>
<script>
    layui.use(['element', "form", 'jquery', 'layer'], function () {
        const form = layui.form;
        const $ = layui.jquery;
        const layer = layui.layer;
        const element = layui.element;
        get_exam_by_e_id_s()
        get_not_finish_exam_user()
        element.on('tab(user_type)', function (data) {
            var type = $(this).attr('value')
            if (type === '0') {
                $("#table_content").html("<table class=\"layui-hide\" id=\"no_finish_user_list\" lay-filter=\"no_finish_user_list\"></table>")
                get_not_finish_exam_user()
            } else if (type === '1') {
                $("#table_content").html("<table class=\"layui-hide\" id=\"finish_user_list\" lay-filter=\"finish_user_list\"></table>")
                get_finish_exam_user()
            }
        });
    });

    function get_exam_by_e_id_s() {
        layui.use(['element', "form", 'jquery', 'layer'], function () {
            const form = layui.form;
            const $ = layui.jquery;
            const layer = layui.layer;
            const element = layui.element;
            const e_id = "${e_id}";
            $.ajax({
                url: 'get_exam_by_e_id_s',
                dataType: "json",//数据格式
                type: "post",//请求方式
                async: false,//是否异步请求
                data: {
                    e_id: e_id
                },
                success: function (data) {
                    if (data.code === 200) {
                        var text = " <table class=\"layui-table\">" +
                            "                        <tbody>" +
                            "                        <tr>" +
                            "                            <th>考试名</th>" +
                            "                            <td>" + data.result.e_name + "</td>" +
                            "                        </tr>" +
                            "                        <tr>" +
                            "                            <th>难度等级</th>" +
                            "                            <td>" + data.result.e_level + "</td>" +
                            "                        </tr>" +
                            "                        <tr>" +
                            "                            <th>所属科目</th>" +
                            "                            <td>" + data.result.subject.s_name + "</td>" +
                            "                        </tr>" +
                            "                        <tr>" +
                            "                            <th>试卷名</th>" +
                            "                            <td>" + data.result.examPaper.ep_name + "</td>" +
                            "                        </tr>" +
                            "                        <tr>" +
                            "                            <th>考试时间</th>" +
                            "                            <td>" + data.result.e_begin_time + "至" + data.result.e_end_time + "</td>" +
                            "                        </tr>" +
                            "                        <tr>" +
                            "                            <th>考试时长</th>" +
                            "                            <td>" + data.result.e_duration + "min</td>" +
                            "                        </tr>" +
                            "                        <tr>" +
                            "                            <th>总分</th>" +
                            "                            <td>" + data.result.e_total_score + "</td>" +
                            "                        </tr>" +
                            "                        <tr>" +
                            "                            <th>创建时间</th>" +
                            "                            <td>" + data.result.e_creat_time + "</td>" +
                            "                        </tr>" +
                            "                        </tbody>" +
                            "                    </table>"
                    }
                    $("#exam_mes").html(text);
                },
                error: function (e) {
                    alert("出现错误！！");
                }
            });

        });
    }

    function get_not_finish_exam_user() {
        layui.use(["form", 'jquery', 'layer', 'table'], function () {
            const $ = layui.jquery;
            const layer = layui.layer;
            const table = layui.table;
            const e_id = "${e_id}";
            table.render({
                elem: '#no_finish_user_list'
                , url: 'get_not_finish_exam_user_by_e_id'
                , where: {e_id: e_id}
                , toolbar: '#toolbarDemo' //开启头部工具栏，并为其绑定左侧模板
                , title: '试题表'
                , cols: [[
                    {field: 'eu_id', title: '考生序号', sort: true}
                    , {field: 'u_sno', title: '考生学号',templet: '<div>{{d.sysUser.u_sno}}</div>'}
                    , {field: 'eu_state', title: '完成状态'}
                    // , {field: 'sa_level', title: '难度等级', templet: '<div>{{d.sysAuthority.a_authority}}</div>'}
                    , {title: '操作', align: 'center', toolbar: '#barDemo'}
                ]]
                , page: {				//分页设置
                    limit: 10,		//默认每一页显示数量
                    limits: [5, 10, 20, 30, 40, 50]		//可选择每页显示的数量
                }
                , parseData: function (res) { //res 即为原始返回的数据
                    var current_pages;
                    //第一次显示的时候this.page=true，把这种情况单独列出
                    if (this.page === true) current_pages = 1;
                    else current_pages = this.page.curr;
                    //根据分页要求选出需要显示的数据
                    let data = res.result.slice(this.limit * (current_pages - 1), this.limit * current_pages);
                    //alert(JSON.stringify(data));
                    return {
                        "code": res.code,
                        "msg": res.message,
                        "count": res.result.length,
                        "data": data
                    }
                }
            });

            //监听行工具事件
            table.on('tool(no_finish_user_list)', function (obj) {
                let data = obj.data;
                console.log(obj)
                if (obj.event === 'del') {
                    layer.confirm('确认移除该考生？', {icon: 0}, function () {
                        $.ajax({
                            url: 'del_exam_user_by_eu_id',
                            dataType: "json",//数据格式
                            type: "post",//请求方式
                            async: false,//是否异步请求
                            data: {
                                eu_id: data.eu_id,
                            },
                            success: function (data) {
                                if (data.code === 200) {
                                    layer.msg(data.message, {icon: 6, time: 1000}, function () {
                                        table.reload('no_finish_user_list', {})
                                    });
                                } else {
                                    layer.msg(data.message, {icon: 5, time: 1000});
                                }
                            },
                            error: function (e) {
                                alert("出现错误！！");
                            }
                        });
                    });
                }
            });

        });
    }


    function get_finish_exam_user() {
        layui.use(["form", 'jquery', 'layer', 'table'], function () {
            const $ = layui.jquery;
            const layer = layui.layer;
            const table = layui.table;
            const e_id = "${e_id}";
            table.render({
                elem: '#finish_user_list'
                , url: 'get_finish_exam_user_by_e_id'
                , where: {e_id: e_id}
                , toolbar: '#toolbarDemo' //开启头部工具栏，并为其绑定左侧模板
                , title: '试题表'
                , cols: [[
                    {field: 'eu_id', title: '考生序号', sort: true}
                    , {field: 'u_sno', title: '考生学号',templet: '<div>{{d.sysUser.u_sno}}</div>'}
                    , {field: 'eu_state', title: '完成状态'}
                    , {field: 'pr_total_score', title: '得分',templet: '<div>{{d.paperResult.pr_total_score}}</div>'}
                    , {field: 'pr_state', title: '审阅状态',templet: '<div>{{d.paperResult.pr_state}}</div>'}
                    // , {field: 'sa_level', title: '难度等级', templet: '<div>{{d.sysAuthority.a_authority}}</div>'}
                    , {title: '操作', align: 'center', toolbar: '#barDemo1'}
                ]]
                , page: {				//分页设置
                    limit: 10,		//默认每一页显示数量
                    limits: [5, 10, 20, 30, 40, 50]		//可选择每页显示的数量
                }
                , parseData: function (res) { //res 即为原始返回的数据
                    var current_pages;
                    //第一次显示的时候this.page=true，把这种情况单独列出
                    if (this.page === true) current_pages = 1;
                    else current_pages = this.page.curr;
                    //根据分页要求选出需要显示的数据
                    let data = res.result.slice(this.limit * (current_pages - 1), this.limit * current_pages);
                    //alert(JSON.stringify(data));
                    return {
                        "code": res.code,
                        "msg": res.message,
                        "count": res.result.length,
                        "data": data
                    }
                }
            });
            //监听行工具事件
            table.on('tool(finish_user_list)', function (obj) {
                let data = obj.data;
                console.log(obj)
                if (obj.event === 'do_review') {
                    if (data.paperResult.pr_state==="已审阅"){
                        layer.alert("已经审阅",{icon:6})
                    }else {
                        layer.confirm('确认审阅？', {icon: 0}, function () {
                            parent.xadmin.add_tab('审批试卷', 'review_exam?eu_id=' + data.eu_id);
                        });
                    }

                }else if(obj.event === 'do_look'){
                    parent.xadmin.add_tab('查看试卷', 'admin_browse_exam_res?eu_id=' + data.eu_id);
                }
            });

        });
    }
</script>
</html>